#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 2e5+50;

int n;

priority_queue<pair<int, int>> pq;

struct Pub
{
	int a, t;

} a[N];



int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i=1; i<=n; ++i)
		scanf("%d", &a[i].a);
	for (int i=1; i<=n; ++i)
		scanf("%d", &a[i].t);

	sort(a+1, a+n+1, [](const Pub &a, const Pub &b){
		return a.a != b.a ? a.a < b.a : a.t > b.t;
	});
	int last = -1e9;
	LL cur = 0, ans = 0;
	for (int i=1, j; i<=n; i=j+1)
	{
		int empty = a[i].a - last - 1;
		int times = min(empty, (int)pq.size());
		// dbg(i, empty, times);
		while (times--)
		{
			ans += cur;
			cur -= pq.top().first;
			pq.pop();
		}
		ans += cur;
		
		cur += a[i].t;
		pq.emplace(a[i].t, a[i].a);
		cur -= pq.top().first;
		pq.pop();

		j = i;
		while (j+1 <= n && a[j+1].a == a[i].a)
			++j;
		for (int k=i+1; k<=j; ++k) {
			cur += a[k].t;
			pq.emplace(a[k].t, a[k].a);
		}

		dbg(i, j, a[i].a, a[i].t, a[j].t, pq.size(), ans);
		last = a[i].a;
	}

	int times = pq.size();
	while (times--)
	{
		ans += cur;
		cur -= pq.top().first;
		pq.pop();
	}
	printf("%lld\n", ans);
	return 0;
}